﻿using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;
using System.Security.Principal;

namespace ProjectFootball.MVC.Areas.MatchArea.Models
{
    public static class _MatchDataModelExtensions
    {
        public static Match CreateNew(this MatchDataModel matchDataModel, IPrincipal user)
        {
            matchDataModel.ApprovalGuid = Guid.NewGuid();

            return matchDataModel.CreateUnapproved(user);
        }

        public static Match CreateUnapproved(this MatchDataModel matchDataModel, IPrincipal user)
        {
            return new Match()
            {
                Pk = Guid.NewGuid(),
                ApprovalGuid = matchDataModel.ApprovalGuid,
                MatchDate = matchDataModel.MatchDate,
                CompetitionGuid = matchDataModel.CompetitionGuid,
                VenueGuid = matchDataModel.VenueGuid,
                Attendance = matchDataModel.Attendance,
                Team1Guid = matchDataModel.Team1Guid,
                Team1HT = (short?)matchDataModel.Team1HT,
                Team1FT = (short?)matchDataModel.Team1FT,
                Team1ETHT = (short?)matchDataModel.Team1ETHT,
                Team1ETFT = (short?)matchDataModel.Team1ETFT,
                Team1Pens = (short?)matchDataModel.Team1Pens,
                Team2Guid = matchDataModel.Team2Guid,
                Team2HT = (short?)matchDataModel.Team2HT,
                Team2FT = (short?)matchDataModel.Team2FT,
                Team2ETHT = (short?)matchDataModel.Team2ETHT,
                Team2ETFT = (short?)matchDataModel.Team2ETFT,
                Team2Pens = (short?)matchDataModel.Team2Pens,
                IsApproved = user.IsApprover(),
                AuditUserId = user.GetUserId(),
                AuditTimestamp = DateTime.Now
            };
        }
    }
}